﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BMSQ.Utility;

namespace BMSQ.Admin.Accounts.Role
{
    public partial class Modify : Page
    {
        private string RoleID
        {
            get
            {
                if (Request.QueryString["roleID"] == null)
                {
                    return "";
                }
                else
                {
                    return Request.QueryString["roleID"].ToString();
                }
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (RoleID == "")
            {
                Response.Write("传入不正确");
                Response.End();
                return;
            }

            if (!Page.IsPostBack)
            {
                if (RoleID != "")
                {
                    ShowInfo();
                }
            }
        }

        private void ShowInfo()
        {
            Vincent.Permission.Model.account_roles model = Vincent.Permission.Functions.Account.GetSingleRole(RoleID);// bll.GetModel(RoleID);
            this.txtRoleName.Text = model.RoleName;
            this.txtDescription.Text = model.Description;

        }

        public void btnSave_Click(object sender, EventArgs e)
        {

            string strErr = "";
            if (this.txtRoleName.Text.Trim().Length == 0)
            {
                strErr += "RoleName不能为空！\\n";
            }
            if (this.txtDescription.Text.Trim().Length == 0)
            {
                strErr += "Description不能为空！\\n";
            }

            if (strErr != "")
            {
                MessageBox.Show(this, strErr);
                return;
            }
            string RoleName = this.txtRoleName.Text;
            string Description = this.txtDescription.Text;


            Vincent.Permission.Model.account_roles model = new Vincent.Permission.Model.account_roles();
            model.RoleID = RoleID;
            model.RoleName = RoleName;
            model.Description = Description;

            Vincent.Permission.Functions.Account.UpdateRole(model);
            MessageBox.ShowAndRedirect(this, "保存成功！", "list.aspx");

        }


        public void btnCancle_Click(object sender, EventArgs e)
        {
            Response.Redirect("list.aspx");
        }
    }
}